/*
 * Copyright (c) 2006, 2021, webrx.cn All rights reserved.
 *
 */
package cn.webrx.controller;

import java.util.Date;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

import cn.webrx.pojo.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringBootVersion;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.thymeleaf.Thymeleaf;

import javax.annotation.Resource;

/**
 * <p>Project: javase - IndexController
 * <p>Powered by webrx On 2021-12-14 08:49:58
 * <p>Created by IntelliJ IDEA
 *
 * @author webrx [webrx@126.com]
 * @version 1.0
 * @since 17
 */
@Controller
public class IndexController {
    @Autowired
    private RedisTemplate<String, Object> redisTemplate;

    @Autowired
    private StringRedisTemplate st;

    @RequestMapping
    public String index(Model m) {
        m.addAttribute("msg", "中文效果");
        m.addAttribute("sv", SpringBootVersion.getVersion());
        m.addAttribute("tv", Thymeleaf.getVersion());
        //var s = st.opsForValue();
        var s = redisTemplate.opsForValue();
        s.set("address", "河南省郑州市");
        m.addAttribute("msg", s.get("address"));

        var l = redisTemplate.opsForList();
        l.leftPushAll("lang", "java程序", "web程序");
        System.out.println(l.range("lang", 0, -1));

        var h = redisTemplate.opsForHash();
        User u = new User();
        u.setId(0);
        u.setName("张三丰");
        u.setMoney(0.0D);
        u.setBirth(LocalDate.now());
        u.setRegtime(new Date());
        u.setLogintime(LocalDateTime.now());
        u.setLogouttme(LocalTime.now());
        Set<String> set = new HashSet<String>();
        set.addAll(List.of("java", "php", "php", "python", "c"));
        u.setLoves(set);
        s.set("user", u);

        return "index";
    }

}
